/* -----------------------------------------------------------------------------
 * PROJECT    : net.lwf
 * FILE       : fVowelFamilyFactory.java
 *
 * HISTORY:
 * Date          Author                        Description
 * ----------------------------------------------------------------------------- 
 * Jan 12, 2009  Raghu Sarraff			       Created
 */
package lwf.factory;

import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.ResourceBundle;
import java.util.StringTokenizer;

public class VowelFamilyFactory {

	private static VowelFamilyFactory instance = null;
	
	private ResourceBundle vowelFamilyBundle = null;
    
	private Map vowelFamilies;
	
	private VowelFamilyFactory() {
        init();
	}
	
	public Map getVowelFamilies() {
		if(vowelFamilies == null) {
			process(vowelFamilyBundle);
		}
		return vowelFamilies;
	}
	
	public synchronized final static VowelFamilyFactory getInstance(){
		if (instance == null) {
			instance = new VowelFamilyFactory();
		}
		return instance;
	}
	
	private void init() {
		if(vowelFamilyBundle == null) {
			vowelFamilyBundle = ResourceBundle.getBundle("general.vowelfamilies");
		}
	}
	
	private void process(ResourceBundle resource) {
		if(vowelFamilies == null) {
			vowelFamilies = new HashMap();
		}
		Enumeration enum1 = resource.getKeys();
		while(enum1.hasMoreElements()) {
			String key = enum1.nextElement().toString(); //a|1
			StringTokenizer stk = new StringTokenizer(key, "|");
			String vowelname = stk.nextToken();
			String voweltype = stk.nextToken();
			
			String data = resource.getString(key);
			StringTokenizer stkdata = new StringTokenizer(data, ",");
			List lstdata = new ArrayList(stkdata.countTokens());
			while(stkdata.hasMoreTokens()) {
				lstdata.add(stkdata.nextToken());
			}
			vowelFamilies.put(vowelname+voweltype, lstdata);
		}
	}
	
} //VowelFamilyFactory

